﻿using System;
using System.Collections.Generic;

namespace Kryptonalysis.Rank
{
    /// <summary>
    /// List of LetterRanks
    /// </summary>
    public abstract class LetterRanks : List<LetterRank>
    {
        /// <summary>
        /// Abstract property to get the language.
        /// </summary>
        /// <value>The language.</value>
        public abstract string Language
        {
            get;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LetterRanks"/> class.
        /// Calls the Fill method.
        /// </summary>
        public LetterRanks()
        {
            Fill();
        }

        /// <summary>
        /// Fills this instance.
        /// </summary>
        protected abstract void Fill();

        /// <summary>
        /// Gets LetterRank the by rank.
        /// </summary>
        /// <param name="rank">The rank.</param>
        /// <returns>LetterRank with specified rank</returns>
        public LetterRank GetByRank(int rank)
        {
            foreach (LetterRank item in this)
                if (item.Rank == rank)
                    return item;
            return null;
        }

        /// <summary>
        /// Gets LetterRank the by sign.
        /// </summary>
        /// <param name="sign">The sign.</param>
        /// <returns>LetterRank with specified sign</returns>
        public LetterRank GetBySign(Char sign)
        {
            foreach (LetterRank item in this)
                if (item.Sign == sign)
                    return item;
            return null;
        }
    }
}
